package dynamicproxy;

import java.lang.reflect.Proxy;

/**
 * @author: knowno
 * @create: 2024-09-23 15:19
 * @Version 1.0
 **/
public class TestAop {
    public static void main(String[] args) {

        //要代理的目标对象
        OrderService orderService = new OrderServiceImpl();

        //创建代理对象
        MyAop myAop = new MyAop(orderService);

        //调用Proxy对象 newProxyInstance
        OrderService myservice = (OrderService) Proxy.newProxyInstance(OrderServiceImpl.class.getClassLoader(),
                new Class<?>[] { OrderService.class },
                myAop);

        //调用方法
        myservice.pay();

        System.out.println("******************************************");
        //要代理的目标对象
        TransService transService = new TransServiceImpl();

        //创建代理对象
        MyAop myAop1 = new MyAop(transService);

        //调用Proxy对象 newProxyInstance
        TransService pService = (TransService) Proxy.newProxyInstance(TransServiceImpl.class.getClassLoader(),
                new Class<?>[] { TransService.class },
                myAop1);

        //调用方法
        pService.trans();

    }
}
